#!/usr/bin/env python
# -*- coding: utf-8 -*-

from django.db import models
from django.core.validators import MaxValueValidator
import os
import sys
import django

sys.path.append(r"web")
sys.path.append(r"algorithm")
sys.path.append(r"cta")

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'adam3.settings')
django.setup()

class CommodityFutureAnalysis(models.Model):
    """
    商品期货分析
    """

    # 主键
    id = models.AutoField(primary_key=True)

    # 代码
    code = models.CharField(max_length=32, db_index=True, null=True, blank=True)

    # 方差类型。variance20表示20日方差，variance60表示60日方差，variance120表示120日方差
    variance_type = models.CharField(max_length=32, db_index=True, null=True, blank=True)

    # 方差取值（使得区分趋势和震荡形态最准确）
    variance_value = models.BigIntegerField(validators=[MaxValueValidator(9223372036854775807)], null=True, blank=True)

    # 均线类型。ma60表示60日均线，ma120表示120日均线，ma250表示250日均线
    ma_type = models.CharField(max_length=32, db_index=True, null=True, blank=True)

    # 均线回溯时间
    ma_backtrack = models.BigIntegerField(validators=[MaxValueValidator(9223372036854775807)], null=True, blank=True)

    # 收益率
    profit_and_loss_rate = models.DecimalField(max_digits=32, decimal_places=3, null=True, blank=True)

    class Meta:
        managed = True
        db_table = 'COMMODITY_FUTURE_ANALYSIS'
        verbose_name = '商品期货分析'
        verbose_name_plural = verbose_name
        # 单列索引
        # indexes = [
        #     models.Index(fields=['code']),
        #     models.Index(fields=['k_line_period_type']),
        #     models.Index(fields=['begin_time']),
        #     models.Index(fields=['end_time']),
        #     models.Index(fields=['name']),
        # ]
        # 联合索引
        # index_together = [('code', 'transaction_date')]